﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ARR.Entities;
using Telerik.Windows.Controls;

namespace ARR.UI.UserControls
{
    /// <summary>
    /// Interaction logic for ArticleMasterGridView.xaml
    /// </summary>
    public partial class ArticleMasterGridView : UserControl
    {
        public ArticleMasterGridView()
        {
            InitializeComponent();

            AttributeTypes = new List<AttributeType>();

            LoadAttributeTypes();
            CompleteGridViewColumns();
        }

        private void LoadAttributeTypes()
        {
            AttributeTypes.Add(new AttributeType { Id = 1, Name = "ConsumptionType", Values = new List<Entities.Attribute>() });
            AttributeTypes.Add(new AttributeType { Id = 2, Name = "SizeSegment", Values = new List<Entities.Attribute>() });
            AttributeTypes.Add(new AttributeType { Id = 3, Name = "Flavour", Values = new List<Entities.Attribute>() });

            AttributeTypes[0].Values.Add(new Entities.Attribute { Id = 1, AttributeTypeId = 1, AttributeValue = "Immediate" });
            AttributeTypes[0].Values.Add(new Entities.Attribute { Id = 2, AttributeTypeId = 1, AttributeValue = "Future" });

            AttributeTypes[1].Values.Add(new Entities.Attribute { Id = 3, AttributeTypeId = 2, AttributeValue = "Single" });
            AttributeTypes[1].Values.Add(new Entities.Attribute { Id = 4, AttributeTypeId = 2, AttributeValue = "Multipack" });

            AttributeTypes[2].Values.Add(new Entities.Attribute { Id = 5, AttributeTypeId = 3, AttributeValue = "Apple" });
            AttributeTypes[2].Values.Add(new Entities.Attribute { Id = 6, AttributeTypeId = 3, AttributeValue = "Chocolate" });
            AttributeTypes[2].Values.Add(new Entities.Attribute { Id = 7, AttributeTypeId = 3, AttributeValue = "Almond" });
            AttributeTypes[2].Values.Add(new Entities.Attribute { Id = 8, AttributeTypeId = 3, AttributeValue = "Strawberry" });
            AttributeTypes[2].Values.Add(new Entities.Attribute { Id = 9, AttributeTypeId = 3, AttributeValue = "Honey" });
        }

        public List<AttributeType> AttributeTypes { get; set; }

        private void CompleteGridViewColumns()
        {   
            foreach (AttributeType type in AttributeTypes)
            {
                GridViewDataColumn col = new GridViewDataColumn { Header = type.Name };                
                DataTemplate viewTemplate = new DataTemplate();
                FrameworkElementFactory textblock = new FrameworkElementFactory(typeof(TextBlock));
                viewTemplate.VisualTree = textblock;
                textblock.SetValue(TextBlock.TextProperty, "Machine.Thumbnail");

                col.CellTemplate = viewTemplate;

                ArticlesGV.Columns.Add(col);
            }
        }
    }
}
